#!/usr/bin/perl
use strict;
use warnings;

use lib '../lib';
use lib '../extlib';
use ChessLike::Board;
use ChessLike::BoardUtils;

use Test::Exception;
use Test::More 'no_plan';

#############
### Parse ###
#############

my $board = ChessLike::Board->parse(
   'sample_files/fairy_board.cfg', 'sample_files' );

## player1
# c1 = knightrider
# d1 = cardinal
# f1 = knightrider
# h2 = zero
## player2
# d7 = amazon
# f7 = amazon
# e8 = zero

my @expected_board = (
   [ 'c1', 0, 'Knightrider', 'n', 1, 0 ],
   [ 'd1', 0, 'Cardinal',    'n', 1, 0 ],
   [ 'f1', 0, 'Knightrider', 'n', 1, 0 ],
   [ 'h2', 0, 'Zero',        'n', 1, 0 ],
   [ 'd7', 0, 'Amazon',      's', 2, 0 ],
   [ 'f7', 0, 'Amazon',      's', 2, 0 ],
   [ 'e8', 0, 'Zero',        's', 2, 0 ],
);

my $iterator = find_tile_contents( $board );

for ( my $i = 0; $i < 7; $i++ ) {
   my @contents = next_tile_contents( $iterator, 'gamepiece', 'direction',
      'team', 'graphic', );
   my @expected = @{ shift( @expected_board ) };
   my $tile = $expected[0];

   is( $contents[0], $tile,  "[parse] $tile: tile" );
   is( $contents[1], $expected[1],  "[parse] $tile: index" );
   is( $contents[2]->name(), $expected[2],  "[parse] $tile: game piece" );
   is( $contents[3], $expected[3],  "[parse] $tile: direction" );
   is( $contents[4], $expected[4],  "[parse] $tile: team" );
   is( @{ $contents[5] }, $expected[5],  "[parse] $tile: graphic" );
}
